package com.itheima.tcp3;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/*
客户端 发送数据
并 接收 服务端的数据
 */
public class Client {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), 1314);

        //获取输出流
        OutputStream os = socket.getOutputStream();
        //字符-> 字节 的形式 输出
        OutputStreamWriter writer = new OutputStreamWriter(os);
        writer.write("你瞅啥");
        writer.flush();
        //其他的办法   单独给一个结束标记
        socket.shutdownOutput();//禁用输出流
        InputStream is = socket.getInputStream();
       //字节-> 字符
        InputStreamReader reader = new InputStreamReader(is);
        int c;
        while ((c=reader.read())!=-1){
            System.out.println((char)c);
        }
        socket.close();

    }
}
